// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class SPECIMEN_IN_PACKAGE_ORL_O40 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("26 SPM",26)]
  	    [HL7Field(HL7Version.v27, 26, HL7Repeat.False, HL7Required.True,"SPM")]
	    public SPM SPM {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("27 SPECIMEN_CONTAINER_IN_PACKAGE",27)]
  	    [HL7Field(HL7Version.v27, 27, HL7Repeat.True, HL7Required.False,"SPECIMEN_CONTAINER_IN_PACKAGE_ORL_O40")]
	    public SPECIMEN_CONTAINER_IN_PACKAGE_ORL_O40[] SPECIMEN_CONTAINER_IN_PACKAGE {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			SPM = PopSegmentParseAndCheckRequired<SPM>(availableData, options, "SPM");
			SPECIMEN_CONTAINER_IN_PACKAGE = ProcessGroupArray<SPECIMEN_CONTAINER_IN_PACKAGE_ORL_O40>(availableData, options, "SPECIMEN_CONTAINER_IN_PACKAGE");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isSPM = availableData.StartsWith("SPM", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("SPM", options.Version) || isSPM) {
				return isSPM;
			}
			SPECIMEN_CONTAINER_IN_PACKAGE_ORL_O40 testSPECIMEN_CONTAINER_IN_PACKAGE_ORL_O40 = new SPECIMEN_CONTAINER_IN_PACKAGE_ORL_O40();
			bool grpCCSPECIMEN_CONTAINER_IN_PACKAGE_ORL_O40 = (testSPECIMEN_CONTAINER_IN_PACKAGE_ORL_O40.CanConsume(availableData, options));
			if (IsRequired("SPECIMEN_CONTAINER_IN_PACKAGE", options.Version) || grpCCSPECIMEN_CONTAINER_IN_PACKAGE_ORL_O40) {
				return grpCCSPECIMEN_CONTAINER_IN_PACKAGE_ORL_O40;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "SPECIMEN_IN_PACKAGE";
			}
        }

        static SPECIMEN_IN_PACKAGE_ORL_O40() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(SPECIMEN_IN_PACKAGE_ORL_O40));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (SPM != null) {
			string segmentValue = SPM.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (SPECIMEN_CONTAINER_IN_PACKAGE != null && SPECIMEN_CONTAINER_IN_PACKAGE.Length > 0) {
			for (int i = 0; i < SPECIMEN_CONTAINER_IN_PACKAGE.Length; i++) {
				string segmentValue = SPECIMEN_CONTAINER_IN_PACKAGE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

